package com.qk.sankuai.inf.leaf.segment.dao;

import com.qk.sankuai.inf.leaf.segment.model.LeafAlloc;
import java.util.List;
import org.apache.ibatis.annotations.*;

public interface IDAllocMapper {

  @Select("SELECT biz_tag, max_id, step, update_time FROM leaf_alloc")
  @Results(
      value = {
        @Result(column = "biz_tag", property = "key"),
        @Result(column = "max_id", property = "maxId"),
        @Result(column = "step", property = "step"),
        @Result(column = "update_time", property = "updateTime")
      })
  List<LeafAlloc> getAllLeafAllocs();

  @Select("SELECT biz_tag, max_id, step FROM leaf_alloc WHERE biz_tag = #{tag}")
  @Results(
      value = {
        @Result(column = "biz_tag", property = "key"),
        @Result(column = "max_id", property = "maxId"),
        @Result(column = "step", property = "step")
      })
  LeafAlloc getLeafAlloc(@Param("tag") String tag);

  @Update("UPDATE leaf_alloc SET max_id = max_id + step WHERE biz_tag = #{tag}")
  void updateMaxId(@Param("tag") String tag);

  @Update("UPDATE leaf_alloc SET max_id = max_id + #{step} WHERE biz_tag = #{key}")
  void updateMaxIdByCustomStep(@Param("leafAlloc") LeafAlloc leafAlloc);

  @Select("SELECT biz_tag FROM leaf_alloc")
  List<String> getAllTags();
}
